package com.wu.controller;

import com.wu.response.CommonReturnType;
import com.wu.service.ArticleReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.wu.constant.Constant.*;

/**
 * 文章举报
 *
 * @author: 吴磊
 * @program: blog
 * @create: 2021-05-12 17:20
 */
@RestController
@Api(tags = "文章举报")
public class ArticleReportController {
    @Autowired
    private ArticleReportService articleReportService;

    /**
     * 添加举报记录
     *
     * @param articleId
     * @param articleTitle
     * @param reportReason
     * @param added
     * @return
     */
    @ApiOperation(value = "根据文章草稿ID删除文章草稿")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "被举报的文章ID", dataTypeClass = String.class),
            @ApiImplicitParam(name = "articleTitle", value = "被举报的文章标题", dataTypeClass = String.class),
            @ApiImplicitParam(name = "reportReason", value = "举报原因", dataTypeClass = String.class),
            @ApiImplicitParam(name = "added", value = "补充说明", dataTypeClass = String.class)})
    @RequestMapping(value = "/insertArticleReport", method = RequestMethod.POST)
    public CommonReturnType insertArticleReport(@RequestParam("articleId") String articleId,
                                                @RequestParam("articleTitle") String articleTitle,
                                                @RequestParam("reportReason") String reportReason,
                                                @RequestParam(name = "added", required = false, defaultValue = DEFAULT_NULL_VALUE) String added) {
        articleReportService.insertArticleReport(articleId, articleTitle, reportReason, added);
        return CommonReturnType.create(null);
    }


    /**
     * type为空就只删除举报
     * 否则还要删除文章
     *
     * @param reportId
     * @param type
     * @return
     */
    @ApiOperation(value = "根据文章草稿ID删除文章草稿")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "举报ID", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "为 null 或者 '' ,如果为空就说明只删除举报，不删除文章", dataTypeClass = String.class)})
    @RequestMapping(value = "/deleteArticleReportById", method = RequestMethod.POST)
    public CommonReturnType deleteArticleReportById(@RequestParam("reportId") String reportId,
                                                    @RequestParam(name = "type", required = false, defaultValue = DEFAULT_NULL_VALUE) String type) {
        articleReportService.deleteArticleReportById(reportId, type);
        return CommonReturnType.create(null);
    }

    /**
     * 获取所有的举报
     *
     * @return
     */
    @ApiOperation(value = "获取所有的举报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页数", defaultValue = ONE, dataTypeClass = String.class)})
    @RequestMapping(value = "/getAllArticleReport", method = RequestMethod.POST)
    public CommonReturnType getAllArticleReport(@RequestParam(name = "curPage", defaultValue = ONE) Integer curPage) {
        Map<String, Object> allArticleReport = articleReportService.getAllArticleReport(curPage);
        return CommonReturnType.create(allArticleReport);
    }


    /**
     * 通过评论Id查看文章明细
     *
     * @param reportId
     * @return
     */
    @ApiOperation(value = "通过评论Id查看文章明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "举报Id", required = true, dataTypeClass = String.class)})
    @RequestMapping(value = "/getArticleReportById", method = RequestMethod.POST)
    public CommonReturnType getArticleReportById(@RequestParam("reportId") String reportId) {
        Map<String, Object> articleReportById = articleReportService.getArticleReportById(reportId);
        return CommonReturnType.create(articleReportById);
    }

}
